package ysq.xyg.sys.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sys.model.po.SysDict;
import ysq.xyg.sys.model.vo.SysDictVo;
import ysq.xyg.sys.service.SysDictService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 系统部分-字典controller层
 *
 * @author shengQiang yu
 * @date 2018-03-18 15:42
 */
@RestController
public class SysDictController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(SysDictController.class);
    @Resource
    private SysDictService sysDictService;

    private SysDict sysDict;

    /**
     * 分页查询
     *
     * @param sysDictVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDict/page",method = RequestMethod.POST)
    public ReturnEntity page(SysDictVo sysDictVo, int pageSize, int pageNum){
        ReturnEntity returnResult = sysDictService.page(sysDictVo,pageSize,pageNum);
        return returnResult;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDict/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/sys/sysDictUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            sysDict = sysDictService.selectByPrimaryKey(id);
            view.addObject("sysDict", sysDict);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDict/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return sysDictService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param sysDictVo Vo对象
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDict/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,SysDictVo sysDictVo){
        return sysDictService.addOrUpdate(sysDictVo,acceptCurrentUser(request));
    }
}